/**
 *  @file SDLPrefetchNode.h
 *
 *  @date 27-dec-2009
 *  @author Ives van der Flaas
 */

#ifndef SDLPREFETCHNODE_H_
#define SDLPREFETCHNODE_H_

#include "tinyxml.h"
#include <string>

namespace si_sdl
{

class SDLPrefetchNode
{
public:
	SDLPrefetchNode(std::string file): fFile(file){}
	/**
	 * Writes it's contents into a subnode.
	 * @param root
	 */
	virtual void write(TiXmlElement* root)=0;

	bool operator==(SDLPrefetchNode& p2)
	{
		return fFile == p2.fFile;
	}

protected:
	std::string fFile;
};

class SDLImagePrefetchNode: public SDLPrefetchNode
{
public:
	SDLImagePrefetchNode(std::string file): SDLPrefetchNode(file){}

	virtual void write(TiXmlElement* root)
	{
		TiXmlElement* me = new TiXmlElement("image");
		TiXmlText* txt = new TiXmlText(fFile.c_str());
		me->LinkEndChild(txt);
		root->LinkEndChild(me);
	}

};

class SDLFontPrefetchNode: public SDLPrefetchNode
{
public:
	SDLFontPrefetchNode(std::string file, int size): SDLPrefetchNode(file), fSize(size){}

	virtual void write(TiXmlElement* root)
	{
		TiXmlElement* me = new TiXmlElement("font");
		me->SetAttribute("size", fSize);
		TiXmlText* txt = new TiXmlText(fFile.c_str());
		me->LinkEndChild(txt);
		root->LinkEndChild(me);
	}

private:
	int fSize;
};

class SDLChunkPrefetchNode: public SDLPrefetchNode
{
public:
	SDLChunkPrefetchNode(std::string file): SDLPrefetchNode(file){}

	virtual void write(TiXmlElement* root)
	{
		TiXmlElement* me = new TiXmlElement("chunk");
		TiXmlText* txt = new TiXmlText(fFile.c_str());
		me->LinkEndChild(txt);
		root->LinkEndChild(me);
	}
};

class SDLMusicPrefetchNode: public SDLPrefetchNode
{
public:
	SDLMusicPrefetchNode(std::string file): SDLPrefetchNode(file){}

	virtual void write(TiXmlElement* root)
	{
		TiXmlElement* me = new TiXmlElement("music");
		TiXmlText* txt = new TiXmlText(fFile.c_str());
		me->LinkEndChild(txt);
		root->LinkEndChild(me);
	}
};
}

#endif /* SDLPREFETCHNODE_H_ */
